<?php

namespace app\admin\controller;

use app\common\controller\AdminController;
use app\admin\service\annotation\ControllerAnnotation;
use app\admin\service\annotation\NodeAnnotation;
use think\App;
use app\Request;
use think\response\Json;

#[ControllerAnnotation(title: 'order')]
class Order extends AdminController
{

    private array $notes;

    public function __construct(App $app)
    {
        parent::__construct($app);
        $this->model = new \app\admin\model\Order();
        $this->notes = $notes = $this->model->notes;
        
        $this->assign(compact('notes'));
    }

    
    #[NodeAnnotation(title: '列表', auth: true)]
    public function index(Request $request): Json|string
    {
        if ($request->isAjax()) {
            if (input('selectFields')) {
                return $this->selectList();
            }
            list($page, $limit, $where) = $this->buildTableParams();
            $where['appid']=$request->adminUserInfo['appid'];
            $count = $this->model->where($where)->count();
            $list  = $this->model->where($where)->page($page, $limit)->order($this->sort)->select()->toArray();
            $data  = [
                'code'  => 0,
                'msg'   => '',
                'count' => $count,
                'data'  => $list,
            ];
            return json($data);
        }
        return $this->fetch();
    }
}